<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>


    <footer th:fragment="table">
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">新闻数据</div>
                            </div>
                            <div class="widget-body  am-fr">
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">

                                                <button type="button" class="am-btn am-btn-default am-btn-success" data-toggle="modal" data-target="#addNews"><span class="am-icon-plus"></span> 添加</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-danger" onclick="delnews()"><span class="am-icon-trash-o"></span> 删除</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field " id="newName" th:value="${newTitle}">
                                        <span class="am-input-group-btn">
                                         <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" th:onclick="selectByNewsName()"></button>
                                    </span>
                                    </div>
                                </div>

                                <div class="am-u-sm-12">
                                     <div style="overflow-x:scroll"><table class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r" style="width: 2000px">
                                         <thead>
                                         <tr>
                                             <th><button onclick="reSelect()" class="am-btn  am-btn-default am-btn-success tpl-table-list-field" type="button">反选</button></th>
                                             <th>编号</th>
                                             <th>行业动态</th>
                                             <th>媒体报告</th>
                                             <th>操作</th>
                                         </tr>
                                         </thead>
                                         <tbody>
                                         <tr class="gradeX" th:each="mynew:${news.list}">
                                             <td><input type="checkbox" name="news" th:value="${mynew.newId}"></td>
                                             <th th:text="${mynew.newId}">编号</th>
                                             <th th:text="${mynew.newTrend}">行业动态</th>
                                             <th th:text="${mynew.newMedia}">媒体报告</th>
                                             <td>
                                                 <div class="tpl-table-black-operation">
                                                     <a href="javascript:" data-toggle="modal" th:data-target="'#'+${mynew.newId}" >修改</a>
                                                     <div class="modal fade" th:id="${mynew.newId}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 300px">
                                                         <div class="modal-dialog">
                                                             <div class="modal-content">
                                                                 <div class="modal-header">
                                                                     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                                     <h4 class="modal-title" id="updateNew">更改信息</h4>
                                                                 </div>
                                                                 <div class="modal-body">
                                                                     <div class="form-group">
                                                                         <label th:for="'mytrend'+${mynew.newId}" class="control-label">行业动态:</label>
                                                                         <input type="text" class="form-control" th:id="'mytrend'+${mynew.newId}" th:value="${mynew.newTrend}">
                                                                     </div>
                                                                     <div class="form-group">
                                                                         <label th:for="'mymedia'+${mynew.newId}" class="control-label">媒体报告:</label>
                                                                         <input type="text" class="form-control" th:id="'mymedia'+${mynew.newId}" th:value="${mynew.newMedia}">
                                                                     </div>
                                                                 </div>
                                                                 <div class="modal-footer">
                                                                     <button type="button" class="btn btn-default" th:onclick="|saveUpdate('${mynew.newId}')|">保存</button>
                                                                 </div>
                                                             </div><!-- /.modal-content -->
                                                         </div><!-- /.modal -->
                                                     </div>
                                                 </div>
                                             </td>
                                         </tr>
                                         </tbody>
                                     </table></div>

                                    <div class="am-u-lg-12 am-cf">
                                        <div class="am-u-lg-3">
                                            跳转至:<input type="number" id="newsPages">/ 页
                                            <span>
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" th:onclick="gonewPages()"></button>
                                        </span>
                                        </div>

                                        <div class="am-fr">

                                            <ul class="am-pagination tpl-pagination">
                                                <li ><a href="javascript:" th:onclick="|gonewspage('${news.navigateFirstPage}')|">首页</a></li>
                                                <li  th:if="news.hasPreviousPage"><a href="javascript:" th:onclick="|gonewspage('${news.prePage}')|">«</a></li>
                                                <li th:each="pageNum:${#numbers.sequence(1,news.pages)}">
                                                    <a th:text="${pageNum}" th:onclick="|gonewspage('${pageNum}')|"></a>
                                                </li>
                                                <li th:if="news.hasNextPage"><a href="javascript:" th:onclick="|gonewspage('${news.nextPage}')|">»</a></li>
                                                <li><a href="javascript:" th:onclick="|gonewspage('${news.navigateLastPage}')|">尾页</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="addNews" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 300px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">添加</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="trend" class="control-label">行业动态:</label>
                                <input type="text" class="form-control" id="trend">
                            </div>
                            <div class="form-group">
                                <label for="media" class="control-label">媒体报告:</label>
                                <input type="text" class="form-control" id="media">
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" onclick="addNews()">添加实时资讯</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
        </div>
    </footer>
    <script>

        //页面跳转
        function gonewspage(pageNum) {
            $.ajax({
                url:"/p2p/newsRecord/selectNewRecord",
                data:{"pageNum":pageNum},
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        function gonewPages() {
            $.ajax({
                url:"/p2p/newsRecord/selectNewRecord",
                data:{"pageNum":$("#newsPages").val(),"newTitle":$("#newName").val()},
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        //条件查询
        function selectByNewsName() {
            $.ajax({
                url:"/p2p/newsRecord/selectNewRecord",
                data:{"newTitle":$("#newName").val()},
                type:"post",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }
        //添加
        function addNews() {
            $.ajax({
                url:"/p2p/newsRecord/addNewRecord",
                data:{"trend":$("#trend").val(),"media":$("#media").val()},
                type:"post",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        //批量删除
        function delnews() {
            var pros = $('input[name="news"]:checked');

            if (pros.html() == undefined) {
                alert('请先选择')
                return;
            }
            var num = [];
            for (var i = 0; i < pros.length; i++) {
                var pro = pros.eq(i);
                pro.parent().parent().remove();//删除页面上对应的列
                num.push(pro.val());
            }
            $.ajax({
                url:"/p2p/newsRecord/delNewsRecord",
                data:{"ids" : num.toString()},
                type:"post",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        function saveUpdate(i) {
            $.ajax({
                url:"/p2p/newsRecord/updateNewsRecord",
                data:{"mytrend":$("#mytrend"+i).val(),"mymedia":$("#mymedia"+i).val(),"newId":i},
                type:"post",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

    </script>
</head>
</html>
